package y24.m5.music.sound;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.io.File;

public class MusicFile {
        public static void main(String[] args) {
            try {
                File musicFile = new File("白月花红.ogg");
                AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(musicFile);
                Clip clip = AudioSystem.getClip();
                clip.open(audioInputStream);

                clip.start();

                // 播放完毕后等待
                while (!clip.isRunning()) {
                    Thread.sleep(10);
                }
                while (clip.isRunning()) {
                    Thread.sleep(10);
                }

                clip.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

}
